package com.zimi.controller;

import com.zimi.model.SysFunctionExtend;
import com.zimi.service.PrivilegeFunctionService;
import com.zimi.util.GsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("授权功能")
@RestController
@RequestMapping("privilege/function")
public class PrivilegeFunctionApi {
    @Autowired
    private PrivilegeFunctionService service;

    @PostMapping("functionTreeList")
    @ApiOperation("查询当前登录人得到授权的功能")
    public Map<String, Object> functionTreeList(HttpServletRequest request) {
        String[] ma = request.getParameterValues("ids");

        List<Integer> posts = GsonUtil.json2Objs(ma[0], Integer.class);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("List", service.functionTreeList(posts));
        map.put("code", 0);
        return map;
    }

    @PostMapping("functionList")
    @ApiOperation("查询用户的授权功能")
    public Map<String, Object> functionList(int userId) {
        List<SysFunctionExtend> data = service.functionList(userId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", data);
        map.put("code", 0);
        return map;
    }
}
